let userlist={
    login:function(value1,value2){
     var p=new Promise(function(resolve,reject){
          $.ajax({url:"../php/login.php",
                  type: "get",
                data:{key:value1,
                    pwd:value2,},
                dataType:"json",
                success:function(e){
                    resolve(e)
                }
        })
     })  
     return p
    },
}

$(".register button").click(function(){
    location.href="register.html"
})
$("#btn").click(function(){
    userlist.login($("#name").val(),$("#pwd").val()).then(function(result){
        if(result.status){
            localStorage.setItem("user",result.user)
            localStorage.setItem("user_id",result.id)
            localStorage.setItem("pwd",result.pwd)
            var backurl=localStorage.getItem("backurl")
            if(backurl){
                localStorage.removeItem("backurl")
                location.href=backurl;
            }
            else{
               location.href="index.html"
            }
        }
        else{
          $(".span_name").html("用户名或密码错误")
        }
    })      
}
)